﻿using System;
using System.Windows;
using Microsoft.Win32;

namespace ToDoList
{
    public class RegistryHandler
    {
        private string strKey;
        private string strValue;

        public RegistryHandler(string strKey, string strValue)
        {
            this.strKey = strKey;
            this.strValue = strValue;
        }

        public bool CheckRegistry()
        {
            RegistryKey startupKey = Registry.CurrentUser.OpenSubKey(strKey);
            bool startUp;

            if (startupKey.GetValue(strValue) == null)
                startUp = false;
            else
                startUp = true;

            return startUp;
        }

        public void ChangeRegistry(bool startUp)
        {
            RegistryKey startupKey = Registry.CurrentUser.OpenSubKey(strKey, true);

            if (startUp)
            {
                startupKey.SetValue(strValue, System.Windows.Forms.Application.ExecutablePath.ToString());
            }
            else if (startupKey.GetValue(strValue) == null)
            {
                // Do nothing
            }
            else
            {
                startupKey.DeleteValue(strValue);
            }
        }
    }
}
